var app = getApp();
//获得全局js变量
var Data = require('../../../utils/data.js');

Page({
  data: {

  },

  changeInputUser: function (e) {
    var value = e.detail.value;
    // console.log(value);
    this.setData({
      userName: value,
    })
  },

  changeInputPw: function (e) {
    var value = e.detail.value;
    // console.log(value);
    this.setData({
      password: value,
    })
  },

  loginAction: function (event) {
    console.log("dsadsad");
    var pw = this.data.password;
    var user = this.data.userName;
    console.log(user);
    console.log(pw);
    wx.showLoading({
      title: '加载中',
      mask: true
    });
    wx.request({
      url: Data.getUrl() + '/user/loginCommon',
      method: 'POST',
      data: {
        phone: user,
        password: pw
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
        // 'Accept': 'application/x-www-form-urlencoded'
      },
      complete: function (res) {
        wx.hideLoading();
      },
      success: function (res) {

        console.log(res);
        wx.hideLoading();
        if (res.data.status == 500) {
          wx.setStorage({
            key: Data.getUserKey(),//"userInfo",
            data: res.data.data
          })
          wx.showToast({
            title: '请求成功',
            icon: 'success',
            mask: true,
          });
          wx.navigateBack({
            delta: 1
          })
        } else {
          wx.showToast({
            title: res.data.data,
            icon: 'error',
            mask: true,
          });
        }
      }
    })
  },
})